set more 1
use ..\data\paper_data.dta, clear
drop if treatment_id==3
xi i.treatment_id*i.part i.economy_type, noomit
global reps=9999
global seed=96941726 // random number
global treatvars _Itreatment_1 _Itreatment_2
label var _Itreatment_1 "Decentralized"
label var _Itreatment_2 "Structured"
label var period "Period number"
label var g "Global geoengineering" 
label var earnings_tot "Total surplus"
label var gini "Gini index"

preserve

* Table D.1: Impacts of Parts 1 and 2 on Part 3 global geoengineering
*====================================================================

collapse g, by(treatment_id economy_id team_id part period)
bysort team_id (period): gen economy_id_n6=economy_id[_N]

forvalues i=1/3{
	bysort economy_id_n6 (team_id period): egen g_pt`i'_a=mean(g) if part==`i'
	bysort economy_id_n6 (team_id period): egen g_pt`i'=max(g_pt`i'_a)
	drop *_a
}
order g_pt*, after(g)
bysort economy_id_n6 (team_id period): egen g_pt12_a=mean(g) if part<3
bysort economy_id_n6 (team_id period): egen g_pt12=max(g_pt12_a)

collapse g_pt*, by(treatment_id economy_id_n6 economy_id period)

est clear

*Run regression 1
local col1 = "col1"
eststo col1: reg g_pt3 g_pt12 if treatment_id==0 & period>=11, cluster(economy_id)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' {
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col1'
}

*Run regression 2
local col2 = "col2"
eststo col2: reg g_pt3 g_pt1 g_pt2 if treatment_id==1 & period>=11, cluster(economy_id)
	lincom g_pt1-g_pt2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' {
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col2'
}
boottest {g_pt1=g_pt2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
estadd scalar p_diffboot=r(p)

*Run regression 3
local col3 = "col3"
eststo col3: reg g_pt3 g_pt1 g_pt2 if treatment_id==2 & period>=11, cluster(economy_id_n6)
	lincom g_pt1-g_pt2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' {
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col3'
}
boottest {g_pt1=g_pt2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
estadd scalar p_diffboot=r(p)

*Export tex
label var g_pt12 "Avg. global geoengineering in Pt. 1 \& 2"
label var g_pt1 "Avg. global geoengineering in Pt. 1"
label var g_pt2 "Avg. global geoengineering in Pt. 2"
esttab `col1' `col2' `col3' using ..\tabs\ordereffects.tex, replace f label booktabs compress nodepvars eqlabels(,) collabels(none) ///
cell(b(fmt(3)) boot_pval(fmt(3) par)) ///
stats(b_diff p_diffboot N N_clust, ///
	fmt(3 3 0 0) ///
	layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
	labels(`"Part 1 $-$ Part 2"' `" "' `"Observations"' `"Economies"')) 

restore
preserve
	
*Table D.2: Effects of Decentralized and Structured in economies of six
*======================================================================

bysort team_id (period): gen economy_id_n6=economy_id[_N]
collapse g earnings_tot gini $treatvars _*par* mistakes* economy_id_n6, by(treatment_id economy_id part period)
gen mistakes=mistakes_pt1+mistakes_pt2+mistakes_pt3

est clear

*Run regression 1
local col1 = "col1"
eststo col1: reg g $treatvars period if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col1'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 2
local col2 = "col2"
eststo col2: reg g $treatvars period mistakes if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col2'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 3
local col3 = "col3"
eststo col3: reg earnings_tot $treatvars period if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col3'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 4
local col4 = "col4"
eststo col4: reg earnings_tot $treatvars period mistakes if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col4'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 5
local col5 = "col5"
eststo col5: reg gini $treatvars if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col5'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 6
local col6 = "col6"
eststo col6: reg gini $treatvars mistakes if part==3, cluster(economy_id)
	lincom _Itreatment_1-_Itreatment_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col6'
}
boottest {_Itreatment_1=_Itreatment_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Export tex
label var _Itreatment_1 "Decentralized"
label var _Itreatment_2 "Structured"
label var mistakes "Mistakes in the quiz"
esttab `col1' `col2' `col3' `col4' `col5' `col6' using ..\tabs\tab_app_effects_n6.tex, replace f label booktabs compress nodepvars eqlabels(,) collabels(none) mgroups("Global geoengineering" "Total surplus" "Gini index", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
cell(b(fmt(3)) boot_pval(fmt(3) par)) ///
stats(b_diff p_diffboot N N_clust, ///
	fmt(3 3 0 0) ///
	layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
	labels(`"Decentralized $-$ Structured"' `" "' `"Observations"' `"Economies"')) 


*Table D.3: Effects of Decentralized and Structured in economies of two
*======================================================================

gen mistakes_pt12=mistakes_pt1+mistakes_pt2
est clear

* Run regression 1
local col1 = "col1"
eststo `col1': reg g _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 period if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col1'
}
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

* Run regression 2
local col2 = "col2"
eststo `col2': reg g _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 period mistakes_pt12 if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col2'
}
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

* Run regression 3
local col3 = "col3"
eststo `col3': reg earnings_tot _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 period if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col3'
}
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

* Run regression 4
local col4 = "col4"
eststo `col4': reg earnings_tot _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 period mistakes_pt12 if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col4'
}
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

* Run regression 5
local col5 = "col5"	
eststo `col5': reg gini _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col5'
}	
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

* Run regression 6
local col6 = "col6"	
eststo `col6': reg gini _Itreatment_1 _Itreatment_2 _Ipart_2 _ItreXpar_1_2 _ItreXpar_2_2 mistakes_pt12 if part<3, cluster(economy_id)
	lincom _ItreXpar_1_2-_ItreXpar_2_2
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
di `n_vars'
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col6'
}	
boottest {_ItreXpar_1_2=_ItreXpar_2_2}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Export tex
label var _Ipart_2 "Part 2"
label var _ItreXpar_1_2 "Part 2 $ \times $ Decentralized" 
label var _ItreXpar_2_2 "Part 2 $ \times $ Structured"
label var mistakes_pt12 "Mistakes in quiz of Parts 1 and 2"
esttab `col1' `col2' `col3' `col4' `col5' `col6' using ..\tabs\tab_app_effects_n2.tex, replace f label booktabs compress nodepvars eqlabels(none) collabels(none) mgroups("Global geoengineering" "Total surplus" "Gini index", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
cell(b(fmt(3)) boot_pval(fmt(3) par)) ///
stats(b_diff p_diffboot N N_clust, ///
	fmt(3 3 0 0) ///
layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
labels(`"Decentralized $-$ Structured in Part 2"' `" "' `"Observations"' `"Economies"')) 

restore
preserve

*Table D.4: Descriptive statistics and tests in parts 1 and 2, by economy type
*=============================================================================

collapse (mean) g gini earnings_tot, by (treatment_id part economy_id economy_type)
mat A=J(1,9,.)
forvalues e=1/3{
ds g earnings_tot gini
foreach v in `r(varlist)'{
		mat B=J(1,9,.)
		sum `v' if treatment_id==0 & part==1 & economy_type==`e'
		mat B[1,1]=r(mean)
		mat B[1,2]=r(sd)
		mat B[1,3]=.
		sum `v' if treatment_id==1 & part==1 & economy_type==`e'
		mat B[1,4]=r(mean)
		mat B[1,5]=r(sd)
		ranksum `v' if treatment_id!=2 & part==1 & economy_type==`e', by(treatment_id)
		mat B[1,6]=r(p)
		sum `v' if treatment_id==2 & part==1 & economy_type==`e'
		mat B[1,7]=r(mean)
		mat B[1,8]=r(sd)
		ranksum `v' if treatment_id!=1 & part==1 & economy_type==`e', by(treatment_id)
		mat B[1,9]=r(p)
		mat A=[A \ B]	
	}
		mat B=J(1,9,.)
		sum g if treatment_id==0 & part==1 & economy_type==`e'
		mat B[1,1]=r(N)
		sum g if treatment_id==1 & part==1 & economy_type==`e'
		mat B[1,4]=r(N)
		sum g if treatment_id==2 & part==1 & economy_type==`e'
		mat B[1,7]=r(N)
		mat A=[A \ B]	
}
forvalues e=1/3{
ds g earnings_tot gini
foreach v in `r(varlist)'{
		mat B=J(1,9,.)
		sum `v' if treatment_id==0 & part==2 & economy_type==`e'
		mat B[1,1]=r(mean)
		mat B[1,2]=r(sd)
		mat B[1,3]=.
		sum `v' if treatment_id==1 & part==2 & economy_type==`e'
		mat B[1,4]=r(mean)
		mat B[1,5]=r(sd)
		ranksum `v' if treatment_id!=2 & part==2 & economy_type==`e', by(treatment_id)
		mat B[1,6]=r(p)
		sum `v' if treatment_id==2 & part==2 & economy_type==`e'
		mat B[1,7]=r(mean)
		mat B[1,8]=r(sd)
		ranksum `v' if treatment_id!=1 & part==2 & economy_type==`e', by(treatment_id)
		mat B[1,9]=r(p)
		mat A=[A \ B]	
	}
		mat B=J(1,9,.)
		sum g if treatment_id==0 & part==2 & economy_type==`e'
		mat B[1,1]=r(N)
		sum g if treatment_id==1 & part==2 & economy_type==`e'
		mat B[1,4]=r(N)
		sum g if treatment_id==2 & part==2 & economy_type==`e'
		mat B[1,7]=r(N)
		mat A=[A \ B]	
}
mat list A
local colnames `"colnames("Mean" "S.D." " p " "Mean" "S.D." " p " "Mean" "S.D." " p ")"'
local rownames "rownames(a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 c0 c1 c2 c3 c4)"
local substitutes `"substitute(a0 " \emph{Part 1} " a1 "Global geoengineering" a2 "Total surplus" a3 "Gini index" a4 "Observations" a5 "Global geoengineering" a6 "Total surplus" a7 "Gini index" a8 "Observations" a9 "Global geoengineering" b0 "Total surplus" b1 "Gini index" b2 "Observations" b3 "Global geoengineering" b4 "Total surplus" b5 "Gini index" b6 "Observations" b7 "Global geoengineering" b8 "Total surplus" b9 "Gini index" c0 "Observations" c1 "Global geoengineering" c2 "Total surplus" c3 "Gini index" c4 "Observations" "& . &" "&  &" "& 6.000 &" "& 6 &" "& 10.000 &" "& 10 &")"'
local beginning "\begin{table}[h!]\centering"
local end1 "\bottomrule\end{tabular}\begin{tablenotes}[para]\footnotesize"
local end2 "\end{tablenotes}\end{threeparttable}\end{table}"
mata: A=st_matrix("A")
local pre_header `"preheader(`beginning'\caption{\textbf{Descriptive statistics and tests in Parts 1 and 2, by economy type \label{tab:test_byecon}}}\begin{threeparttable}\begin{tabular}{lr@{ }llr@{ }llr@{ }ll}\toprule &\multicolumn{2}{c}{Baseline}&&\multicolumn{2}{c}{Decentralized}&&\multicolumn{2}{c}{Structured}&\\)"'
local bottom `"bottom( `end1' \item \textit{Note:} $ p $-values refer to Wilcoxon-Mann-Whitney exact tests of Baseline vs. Decentralized and Baseline vs. Structured. The null hypothesis is that the samples come from the same population. The unit of observation for Global geoengineering, and Total surplus is the average outcome in an economy in a part. Gini index is computed on cumulative earnings in the last round of each part. `end2' )"'
mmat2tex A using ..\tabs\tab_app_avg_tests_byecon.tex, replace fmt(%12.3f) insertendrow(2 " \midrule \emph{Economy} ($ L,M$) & \\ " 7 " \emph{Economy} ($ L,H$) & \\ " 11 " \emph{Economy} ($ M,H$) & \\ " 15 " \addlinespace \emph{Part 2} & \\ \emph{Economy} ($ L,M$) & \\ " 19 " \emph{Economy} ($ L,H$) & \\ " 23 "  \emph{Economy} ($ M,H$) & \\ ")  `colnames' `rownames' `substitutes' `pre_header' `bottom'

restore
preserve

* Table D.5: Global geoengineering--Part 1 vs. Part 2
*====================================================

gen g_pt1=g if part==1
gen g_pt2=g if part==2
collapse g g_pt* if part<3, by (treatment_id economy_id economy_type)

mat A=J(1,15,.)
forvalues e=1/3{
	mat B=J(1,15,.)
	sum g_pt1 if treatment_id==0 & economy_type==`e'
	mat B[1,1]=r(mean)
	mat B[1,2]=r(sd)
	sum g_pt2 if treatment_id==0 & economy_type==`e'
	mat B[1,4]=r(mean)
	mat B[1,5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==0 & economy_type==`e'
	mat B[1,3]=r(p)
	
	sum g_pt1 if treatment_id==1 & economy_type==`e'
	mat B[1,5+1]=r(mean)
	mat B[1,5+2]=r(sd)
	sum g_pt2 if treatment_id==1 & economy_type==`e'
	mat B[1,5+4]=r(mean)
	mat B[1,5+5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==1 & economy_type==`e'
	mat B[1,5+3]=r(p)
	
	sum g_pt1 if treatment_id==2 & economy_type==`e'
	mat B[1,5*2+1]=r(mean)
	mat B[1,5*2+2]=r(sd)
	sum g_pt2 if treatment_id==2 & economy_type==`e'
	mat B[1,5*2+4]=r(mean)
	mat B[1,5*2+5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==2 & economy_type==`e'
	mat B[1,5*2+3]=r(p)
	
	mat A=[A \ B]	
}
	mat B=J(1,15,.)
	sum g_pt1 if treatment_id==0
	mat B[1,1]=r(mean)
	mat B[1,2]=r(sd)
	sum g_pt2 if treatment_id==0
	mat B[1,4]=r(mean)
	mat B[1,5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==0
	mat B[1,3]=r(p)
	
	sum g_pt1 if treatment_id==1
	mat B[1,5+1]=r(mean)
	mat B[1,5+2]=r(sd)
	sum g_pt2 if treatment_id==1
	mat B[1,5+4]=r(mean)
	mat B[1,5+5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==1
	mat B[1,5+3]=r(p)
	
	sum g_pt1 if treatment_id==2
	mat B[1,5*2+1]=r(mean)
	mat B[1,5*2+2]=r(sd)
	sum g_pt2 if treatment_id==2
	mat B[1,5*2+4]=r(mean)
	mat B[1,5*2+5]=r(sd)
	signrank g_pt1=g_pt2 if treatment_id==2
	mat B[1,5*2+3]=r(p)
	
	mat A=[A \ B]	
mat list A
local colnames `"colnames("Mean" "(S.D.)" " p " "Mean" "(S.D.)" "Mean" "(S.D.)" " p " "Mean" "(S.D.)" "Mean" "(S.D.)" " p " "Mean" "(S.D.)")"'
local rownames "rownames(a0 a1 a2 a3 a4)"
local substitutes `"substitute(a0 " " a1 " ( $ L,M $ ) " a2 " ( $ L,H $ ) " a3 " ( $ M,H $ ) " a4 "All")"'
local beginning "\begin{table}[h!]\centering\small"
local end1 "\bottomrule\end{tabular}\begin{tablenotes}[para]\footnotesize"
local end2 "\end{tablenotes}\end{threeparttable}\end{table}"
mata: A=st_matrix("A")
local pre_header `"preheader(`beginning'\caption{\textbf{Descriptive statistics and tests--Part 1 vs. Part 2\label{tab:avg_tests_pt1vspt2}}}\begin{threeparttable}\begin{tabular}{l l@{ }lcl@{ }l l@{ }lcl@{ }l l@{ }lcl@{ }l}\toprule &\multicolumn{5}{c}{Baseline}&\multicolumn{5}{c}{Decentralized}&\multicolumn{5}{c}{Structured}\\)"'
local bottom `"bottom( `end1' \item \textit{Note:} \textit{Note:} $ p $-values refer to Wilcoxon-Mann-Whitney exact tests of Baseline vs. Decentralized and Baseline vs. Structured. The null hypothesis is that the samples come from the same population. The unit of observation for Global geoengineering, and Total surplus is the average outcome in an economy in a part. Gini index is computed on cumulative earnings in the last round of each part. `end2' )"'
mmat2tex A using ..\tabs\avg_tests_pt1vspt2.tex, replace fmt(%12.3f) insertendrow(2 " \midrule ") `colnames' `rownames' `substitutes' `pre_header' `bottom'

restore
preserve

* Table E.1: Descriptive statistics and tests in Structured under N=6 with and without bug
*=========================================================================================

gen treatment_id2=treatment_id
replace treatment_id2=3 if date=="180618_0927" | (date=="180618_1428" & economy_id==61) | date=="180620_0947"

collapse g earnings_tot gini if part==3 & treatment_id2>1, by(treatment_id2 economy_id)

mat A=J(1,5,.)
ds g earnings_tot gini
foreach v in `r(varlist)'{
		mat D=J(1,5,.)
		sum `v' if treatment_id2==2
		mat D[1,1]=r(mean)
		mat D[1,2]=r(sd)
		sum `v' if treatment_id2==3
		mat D[1,4]=r(mean)
		mat D[1,5]=r(sd)
		ranksum `v', by(treatment_id2)
		mat D[1,3]=r(p)
		mat A=[A \ D]	
}
		mat D=J(1,5,.)
		sum g if treatment_id2==2
		mat D[1,1]=r(N)
		sum g if treatment_id2==3
		mat D[1,4]=r(N)
		mat A=[A \ D]	
mat list A
local colnames `"colnames("Mean" "S.D." " p " "Mean" "S.D.")"'
local rownames "rownames(a0 a1 a2 a3 a4)"
local substitutes `"substitute(a1 "Global geoengineering" a2 "Total surplus" a3 "Gini index" a4 "Observations")"'
local beginning "\begin{table}[h!]\centering"
local end1 "\bottomrule\end{tabular}\begin{tablenotes}[para]\footnotesize"
local end2 "\end{tablenotes}\end{threeparttable}\end{table}"
mata: A=st_matrix("A")
local pre_header `"preheader(`beginning'\caption{\textbf{Descriptive statistics and tests in Part 3 of Structured \label{tab:test_robcheck_structured}}}\begin{threeparttable}\begin{tabular}{lr@{ }llr@{ }llr@{ }ll}\toprule &\multicolumn{2}{c}{Structured-OK}&&\multicolumn{2}{c}{Structured-BUG}\\)"'
local bottom `"bottom( `end1' \item \textit{Note:} $ p $-values refer to Wilcoxon-Mann-Whitney exact tests of Baseline vs. Transfer and Baseline vs. Structured. The null hypothesis that the samples come from the same population. The unit of observation for Global geoengineering, and Total surplus is the average outcome in an economy in a part. Gini index is computed on cumulative earnings in the last round of each part. `end2' )"'
mmat2tex A using ..\tabs\avg_tests_robcheck_struct.tex, replace fmt(%12.3f) insertendrow(2 " \midrule ")  `colnames' `rownames' `substitutes' `pre_header' `bottom'

restore
preserve

* Table E.2: Effects of Decentralized and Structured under N=6--Bug in Structured
*================================================================================

gen treatment_id2=treatment_id
replace treatment_id2=3 if date=="180618_0927" | (date=="180618_1428" & economy_id==61) | date=="180620_0947"
xi i.treatment_id2, noomit
global treatvars2 _Itreatment_2 _Itreatment_3 _Itreatment_1

collapse g earnings_tot gini _Itreatment* if part==3, by(treatment_id2 economy_id period)

*Run regression 1
local col1 = "col1"
eststo col1: reg g $treatvars2 period, cluster(economy_id)
	lincom _Itreatment_2-_Itreatment_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col1'
}
boottest {_Itreatment_2=_Itreatment_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 2
local col2 = "col2"
eststo col2: reg earnings_tot $treatvars2 period, cluster(economy_id)
	lincom _Itreatment_2-_Itreatment_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col2'
}
boottest {_Itreatment_2=_Itreatment_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 3
local col3 = "col3"
eststo col3: reg gini $treatvars2, cluster(economy_id)
	lincom _Itreatment_2-_Itreatment_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col3'
}
boottest {_Itreatment_2=_Itreatment_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)
label var _Itreatment_1 "Decentralized"
label var _Itreatment_2 "Structured no bug"
label var _Itreatment_3 "Structured bug"
label var period "Period number"
esttab `col1' `col2' `col3' using ..\tabs\effects_n6_robcheck_struct.tex, replace f label booktabs compress nodepvars eqlabels(none) collabels(none) ///
mtitles( "Global geoengineering" "Total surplus" "Gini index")  ///
cell(b(fmt(3)) boot_pval(fmt(3) par)) ///
stats(b_diff p_diffboot N N_clust, ///
	fmt(3 3 0 0) ///
	layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
	labels(`"Structured: no bug $-$ bug"' `" "' `"Observations"' `"Economies"')) 

restore
preserve

* Table G.1: Average teams' effort by economy type and part
*==========================================================

collapse g_team _Ipart_*, by (treatment_id economy_type gstar economy_id team_id part period)
bysort team_id (period): gen economy_id_n6=economy_id[_N]
bysort team_id (period): gen economy_type_n2=economy_type[1]

forval t=0/2{
	di "*********** treatment = `t' ********* "
	di "**** LM & L ****"
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==1 & gstar==2, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
	di "**** LM & M ****"
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==1 & gstar==6, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
	di "**** LH & L ****"	
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==2 & gstar==2, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
	di "**** LH & H ****"		
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==2 & gstar==10, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
	di "**** MH & M ****"	
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==3 & gstar==6, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
	di "**** MH & H ****"
	qui reg g_team _Ipart_2 _Ipart_3 period if treatment_id==`t' & economy_type_n2==3 & gstar==10, cluster(economy_id_n6)
	boottest {_Ipart_2} {_Ipart_2=_Ipart_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id_n6)
}

gen g_team_pt1_base=g_team if part==1 & treatment_id==0
gen g_team_pt2_base=g_team if part==2 & treatment_id==0
gen g_team_pt3_base=g_team if part==3 & treatment_id==0
gen g_team_pt1_dec=g_team if part==1 & treatment_id==1
gen g_team_pt2_dec=g_team if part==2 & treatment_id==1
gen g_team_pt3_dec=g_team if part==3 & treatment_id==1
gen g_team_pt1_stru=g_team if part==1 & treatment_id==2
gen g_team_pt2_stru=g_team if part==2 & treatment_id==2
gen g_team_pt3_stru=g_team if part==3 & treatment_id==2
bysort team_id (period): replace economy_id=economy_id[1] if period>10
bysort team_id (period): replace economy_type=economy_type[1] if period>10
sort economy_type gstar
egen economy_type_gstar=group(economy_type gstar)

mat A=[.,.,.,.,.,.]
ds g_team_pt1_base g_team_pt2_base g_team_pt3_base g_team_pt1_dec g_team_pt2_dec g_team_pt3_dec g_team_pt1_stru g_team_pt2_stru g_team_pt3_stru
foreach v in `r(varlist)'{
	forvalue i=1/6{
		sum `v' if economy_type_gstar==`i'
		sca `v'_tr`i'_mean=r(mean)
	}
	mat B=[.,.,.,.,.,. \ .,.,.,.,.,.]
	forvalue i=1/6{
		mat B[1,`i']=`v'_tr`i'_mean
	}	
	mat A=[A \ B]
}
mat list A
local colnames `"colnames("IP2" "IP6" "IP2" "IP10" "IP6" "IP10")"'
local rownames "rownames(a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 b0 b1 b2 b3 b4 b5 b6 b7)"
local substitutes `"substitute(a0 "" a1 "Part 1" a2 "" a3 "Part 2" a4 "" a5 "Part 3" a6 "" a7 "Part 1" a8 "" a9 "Part 2" b0 "" b1 "Part 3" b2 "" b3 "Part 1" b4 "" b5 "Part 2" b6 "" b7 "Part 3")"'
local beginning "\begin{table}[h!]\centering"
local end1 "\bottomrule\end{tabular}\begin{tablenotes}[para]\footnotesize"
local end2 "\end{tablenotes}\end{threeparttable}\end{table}"
mata: A=st_matrix("A")
local pre_header `"preheader(`beginning'\caption{\textbf{Teams effort choices by economy type and part}\label{tab:g2_mwt}}\begin{threeparttable}\begin{tabular}{l*{6}{C{1.5cm}}}\toprule)"'
local bottom `"bottom( `end1' \item \textit{Note:} The unit of observation is a team in a round. $ < $, $ \ll $, and $ \lll $ refer to $ p < 0.1 $, $ p < 0.05 $, and $ p < 0.01 $, respectively; wild bootstrap  $ p $-values refer to linear regressions of the effort decision on dummy variables for Part 2 and Part 3 and a linear period trend with standard errors clustered at the economy level (the economy is that in Part 3). Wild bootstrap $p$-values derived from running 9,999 replications in each case, clustered at the economy level. `end2' )"'
mmat2tex A using ..\tabs\tab_app_efforts.tex, replace fmt(%12.3f) insertendrow(2 "\midrule") `colnames' `rownames' `substitutes' `pre_header' `bottom'

restore
preserve

* Table G.2: Factors behind making and taking offers for economies of two
*========================================================================

gen take_offer=.
replace take_offer=0 if treatment_id>0 & transfers_received==0 & amount_opponent<.
replace take_offer=1 if treatment_id>0 & transfers_received==amount_opponent & amount_opponent<.
gen mistakes_pt12=mistakes_pt1+mistakes_pt2
gen negrec=0.6261938/2*negrecip3+0.6261938/2*negrecip2+0.3738062*negrecip1
gen altruism=0.6350048*altruism2+0.3649952*altruism1
replace request_opponent=request_opponent-1 if part==2 & sign_opponent==-1 & high_gstar==1
replace request_opponent=gstar if part==2 & sign_opponent==1 & high_gstar==1

collapse mistakes_pt12 gstar amount_team request_team take_offer request_opponent amount_opponent gstar_opponent offer_made high_gstar altruism negrec risk _Ieconomy_t_* if treatment_id>0 & part==2, by (treatment_id economy_id team_id period) 

gen profitable_sender=.
replace profitable_sender=0 if request_team!=.
replace profitable_sender=1 if request_team!=. & -10*abs(gstar-request_team)-amount_team>=-10*abs(gstar-gstar_opponent)
replace profitable_sender=0 if request_team!=. & high_gstar==1

gen profitable_recipient=.
replace profitable_recipient=0 if request_opponent!=.
replace profitable_recipient=1 if request_opponent!=. & high_gstar==1 & -4*request_opponent-10*abs(gstar-request_opponent)+amount_opponent>=-4*gstar
replace profitable_recipient=1 if request_opponent!=. & high_gstar==0 & -4*request_opponent-10*abs(gstar-gstar_opponent  )+amount_opponent>=-10*(gstar-gstar_opponent)

bysort treatment_id economy_id period (gstar): gen profitable_both=profitable_sender[1]+profitable_recipient[2] if _n==1
bysort treatment_id economy_id period (gstar): replace profitable_both=0 if _n==2 & request_team!=.

gen offer_made_profit=offer_made==1 & profitable_sender==1
replace offer_made_profit=. if treatment_id==2 & high_gstar==1
gen offer_made_profit2=offer_made==1 & profitable_both==2
replace offer_made_profit2=. if treatment_id==2 & high_gstar==1

sort treatment_id economy_id period gstar
order treatment_id economy_id team_id period gstar offer_made offer_made_profit amount_team request_team profitable_sender amount_opponent request_opponent profitable_recipient profitable_both

est clear

*Run regression 1
local col1 = "col1"
eststo col1: reg offer_made negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==1, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col1'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 2
local col2 = "col2"
eststo col2: reg offer_made negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==2, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col2'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 3
local col3 = "col3"
eststo col3: reg offer_made_profit2 negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==1 & offer_made==1, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col3'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 4
local col4 = "col4"
eststo col4: reg offer_made_profit2 negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==2 & offer_made==1, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col4'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 5
local col5 = "col5"
eststo col5: reg take_offer  request_opponent amount_opponent negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==1, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col5'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

*Run regression 6
local col6 = "col6"
eststo col6: reg take_offer  request_opponent amount_opponent negrec altruism risk mistakes_pt12 period _Ieconomy_t_2 _Ieconomy_t_3 if treatment_id==2, cluster(economy_id)
	lincom _Ieconomy_t_2-_Ieconomy_t_3
	estadd scalar b_diff=r(estimate)
*Bootstrap 
local indep_vars: colnames e(b)
local n_vars: colsof e(b)
local indep_hypotheses
foreach var of local indep_vars {
	local indep_hypotheses = "`indep_hypotheses' {`var'}"
}
boottest `indep_hypotheses', boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
matrix boot_pval  = J(1,`n_vars',.)
forval k = 1/`n_vars' { 
	matrix boot_pval[1,`k'] = r(p_`k')
}
foreach mat in "boot_pval"{
	matrix colnames `mat' = `indep_vars'
	estadd matrix `mat' = `mat': `col6'
}
boottest {_Ieconomy_t_2=_Ieconomy_t_3}, boottype(wild) weighttype(webb) reps($reps) seed($seed) noci nograph cluster(economy_id)
estadd scalar p_diffboot=r(p)

label var negrec "Negative reciprocity"
label var altruism "Altruism"
label var mistakes_pt12 "Mistakes in quiz of Parts 1 and 2"
label var amount_opponent "Offered amount"
label var request_opponent "Requested effort"
label var risk "Proneness to risk taking"
label var _Ieconomy_t_2 "Economy ($ L,H$)"
label var _Ieconomy_t_3 "Economy ($ M,H$)"
esttab using ..\tabs\tab_app_correlatesoffers.tex, replace f label eqlabels(, none) booktabs noomitted lines nobaselevels alignment(D{.}{.}{-1}) ///
cell(b(fmt(3)) boot_pval(fmt(3) par)) ///
stats(b_diff p_diffboot N N_clust, ///
	fmt(3 3 0 0) ///
layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
labels(`"$ (L, H) - (M, H) $ economy"' `" "' `"Observations"' `"Economies"')) ///
order(mistakes_pt12* negrec altruism risk request_opponent amount_opponent period _Ieconomy_t*)